/**
 * displayobject utilities
 * Copyright (c) 2009 cmiscm.com
 * date of final modification : 2008. 08. 24 
*/
package com.cmiscm.utils.common
{	
	import flash.display.*;
	import flash.utils.getDefinitionByName;
	
	/**
	 * DisplayObject Utilities.
     * 
     */
	public class DisplayObjectUtilities 
	{		
		/**
		 * Remove all of children in a container
		 * @param $container DisplayObjectContainer
		 * 
		 */		
		public static function removeAllChildren($container:DisplayObjectContainer):void 
		{
			var count:int = $container.numChildren;			
			for (var i:int=0; i<count; i++) $container.removeChildAt(0);
		}
		
		/**
		 * Get HTML parameters
		 * @param $stage Stage
		 * @param $name Parameters Name
		 * @param $local HTML에 Parameters가 없을때 불러올 경로
		 * @return 
		 * 
		 */			
		public static function setParameters($stage:Stage, $name:String, $local:String):String
		{
			var url:String = String($stage.loaderInfo.url).slice(0, 4);
			var obj:Object = LoaderInfo($stage.loaderInfo).parameters;
			
			if (obj[$name] == undefined && url == "file") return $local;
			else return String(obj[$name]);
		}
		
		/**
		 * 라이브러리 등에 생성해 놓은 클래스 명이 A1,A2,A3....A100 인데 이 모두를 new 로 선언해서 배열에 담아서 리턴
		 * @param $str Linkage Name
		 * @param $start Start Number
		 * @param $end End Number
		 * @return 
		 * 
		 */			
		public static function GetClassByName($str:String, $start:int, $end:int):Array
		{
			var classArr:Array = [];
			for (var i:int=$start; i<=$end; i++) {
				classArr[i] = new (getDefinitionByName($str + i) as Class);			
			}
			return classArr;
		}
		
		/**
		 * Appoint hit area 
		 * @param $mc MC Sprite
		 * @param $hit HitArea Sprite
		 * @param $btMode Button Mode
		 * 
		 */		
		public static function hitArea($mc:Sprite, $hit:Sprite, $btMode:Boolean = true):void
		{
			$mc.buttonMode = $btMode;
			$hit.visible = false;
			$hit.mouseEnabled = false;
			$mc.hitArea = $hit;
		}
	}
}